import java.util.Arrays;

public class array {
    public static void func1(){
        int [] array1 = {1, 2, 3};
        int [] array2 = {1, 2, 3, 4, 5};
        array2[0] = 100;
        array2[1] = 200;
        array1 = array2;
        array1[2] = 300;
        array1[3] = 400;
        array1[4] = 500;
        for(int i = 0; i < array1.length; i++){
            System.out.println(array1[i]);
        }
    }
    public static void func2(int [] array){
        array = new int[10];
    }
    public static void func3(int [] array){
        array[0] = 99;
    }
    //toString的实现
    public static String myToString(int [] array){
        String s = "[";
        for (int i = 0; i < array.length; i++){
            s += array[i];
            if(i != array.length - 1){
                s += ",";
            }
        }
        s += "]";
        return s;
    }
    //实现查找功能
    public static int search(int [] arr, int x){
        int left = 0;
        int right = arr.length-1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(x < arr[mid]){
                //位于左侧
                right = mid - 1;
            } else if (x > arr[mid]) {
                //位于右侧
                left = x + 1;
            } else {
                //找到了
                return mid;
            }
        }
        //循环结束，未找到
        return -1;
    }
    //打印二维数组
    //动态获取二维数组行列长度
    public static void outPut(int [][] arr){
        for(int i = 0; i < arr.length; i++){
            for(int j = 0; j < arr[0].length; j++){
                System.out.print(arr[i][j] + " ");
            }
            System.out.println();
        }
    }
    public static void main(String[] args) {
        int [][] array = {{1, 2}, {3, 4}};
        outPut(array);
        System.out.println(Arrays.deepToString(array));
//        func1();
//        String ret = myToString(array);
//        System.out.println(ret);
//        System.out.println(search(array , 5));
    }

}
